/**
* @author:kellen
* @contact:xiekellen@hotmail.com
* @company:achivo-gz
* @created on:
* @modified on:
*/

package com.sasis.dao.ibatis;

import java.util.List;

import com.sasis.dao.ibatis.BaseDaoiBATIS;
import com.sasis.model.FlightTransferWait;
import com.sasis.dao.FlightTransferWaitDao;

import org.springframework.orm.ObjectRetrievalFailureException;

public class FlightTransferWaitDaoiBatis extends BaseDaoiBATIS implements FlightTransferWaitDao {

    /**
     * @see com.sasis.dao.FlightTransferWaitDao#getFlightTransferWaits(com.sasis.model.FlightTransferWait)
     */
    public List getFlightTransferWaits(final FlightTransferWait flightTransferWait) {
          return getSqlMapClientTemplate().queryForList("getFlightTransferWaits", flightTransferWait);
    }

    /**
     * @see com.sasis.dao.FlightTransferWaitDao#getFlightTransferWait(Integer id)
     */
    public FlightTransferWait getFlightTransferWait(Integer id) {
        FlightTransferWait flightTransferWait = (FlightTransferWait) getSqlMapClientTemplate().queryForObject("getFlightTransferWait", id);

        //if (flightTransferWait == null) {
            //throw new ObjectRetrievalFailureException(FlightTransferWait.class, id);
        //}

        return flightTransferWait;
    }

    /**
     * @see com.sasis.dao.FlightTransferWaitDao#saveFlightTransferWait(FlightTransferWait flightTransferWait)
     */    
    public int saveFlightTransferWait(final FlightTransferWait flightTransferWait) {
        Integer id = flightTransferWait.getId();
        // check for new record
        if (id == null) {
            id = (Integer) getSqlMapClientTemplate().insert("addFlightTransferWait", flightTransferWait);
        } else {
            getSqlMapClientTemplate().update("updateFlightTransferWait", flightTransferWait);
        }
        if( id == null ) {
            throw new ObjectRetrievalFailureException(FlightTransferWait.class, id);
        }
        return id.intValue();
    }

    /**
     * @see com.sasis.dao.FlightTransferWaitDao#removeFlightTransferWait(Integer id)
     */
    public void removeFlightTransferWait(FlightTransferWait flightTransferWait) {
        getSqlMapClientTemplate().update("deleteFlightTransferWait",  flightTransferWait);
    }
}
